<template>
	<view>
		<view class="d-flex j-start  flex-column  main-bg-color" style="height: 220rpx;">
			<view class="mt-3 d-flex a-center " style="padding: 0 0 0 30rpx;">
				<image src="../../static/image/sheshi3.png" mode="widthFix" style="width: 30rpx;height: 30rpx;"></image>
				<view class="font" style="color: #A9B4FF;padding: 0 0 0 20rpx;">
					单位名称
				</view>
			</view>
			<view class="mt-1 d-flex j-sb " style="padding: 0 0 0 30rpx;font-size: 32rpx;">
				<view class="font" style="color: #fff;padding: 0 0 0 20rpx;">
					{{user_list.deptName}}
				</view>
			</view>
			<view class="mt-1 d-flex a-center " style="padding: 0 0 0 30rpx;">
				<image src="../../static/image/my2.png" mode="widthFix" style="width: 30rpx;height: 30rpx;"></image>
				<view class="font" style="color: #A9B4FF;padding: 0 0 0 20rpx;">
					渠道商:<text style="margin-left: 20rpx;">{{user_list.distributorName}}</text>
				</view>
			</view>
		</view>
		<!-- <button  open-type="contact" ></button> -->
		<view open-type="contact" class="d-flex flex-column pb-4 pt-5 border-bottom" style="width: 90%;margin: 0 auto;">
			<view class="d-flex a-center ">
				<input type="text" v-model="update_list.phonenumber" placeholder="请输入联系电话"
					@input="update_phonenumber"></input>
				<image src="../../static/image/jiantouyou.png" mode="widthFix"
					style="width: 18rpx;height: 18rpx;position: relative;left:50%;"></image>
			</view>
		</view>
		<view class="d-flex flex-column pb-4 pt-5 border-bottom" style="width: 90%;margin: 0 auto;">
			<view class="d-flex a-center ">
				<input type="text" v-model="update_list.deptName" placeholder="请输入单位地址"
					@input="update_deptName"></input>
				<image src="../../static/image/jiantouyou.png" mode="widthFix"
					style="width: 18rpx;height: 18rpx;position: relative;left:50%;"></image>
			</view>
		</view>
		<view class="main-bg-color d-flex j-center a-center"
			style="width: 690rpx;height:92rpx ;color: #FFFFFF;border-radius: 50rpx;position: absolute;bottom: 140rpx;left: 4%;"
			@tap="btn_show">
			完成
		</view>
		<wyb-popup ref="popup" type="center" height="344" width="600" radius="8" :showCloseIcon="false">
			<view class="popup-content d-flex j-center"
				style="margin-top: 70rpx;color: #000000;font-size: 32rpx;font-weight: bold;font-family: PingFangSC-Medium, PingFang SC;">
				确认修改并提交审核?
			</view>
			<view class="d-flex j-center a-center" style="margin-top: 80rpx;">
				<view class="d-flex j-center a-center mr-1" @tap="is_hide"
					style="width: 240rpx;height: 80rpx;border-radius: 10rpx;border: 1px solid #4A67DF;color:#4A67DF ;">
					取消
				</view>
				<view class="d-flex j-center a-center ml-1" @tap="agree"
					style="width: 240rpx;height: 80rpx;border-radius: 10rpx;background: #4A67DF;color: #fff;">
					确认
				</view>
			</view>
		</wyb-popup>
	</view>
</template>

<script>
	import wybPopup from '@/components/wyb-popup/wyb-popup.vue'
	export default {
		components: {
			wybPopup
		},
		data() {
			return {
				phone: '',
				poshition: '',
				show: false,
				user_list: {},
				update_list: {
					//修改维保的手机号
					phonenumber: '',
					//修改维保的地址
					deptName: ''
				}
			};
		},
		onLoad() {

		},
		onShow() {
			//获取维保单位名称和渠道商
			this.getuser_list()
		},
		methods: {
			//获取维保单位信息
			getuser_list() {
				this.$https.get('getMaintainUserInfo/', {
					Authorization: uni.getStorageSync("token")
				}).then(res => {
					this.user_list = res.user
					console.log(this.user_list);
				})
			},
			//获取填写电话
			update_phonenumber(e) {
				this.$nextTick(() => {
					// this.update_list.phonenumber = e.detail.value.replace(/\D/g, '')
					this.update_list.phonenumber = e.detail.value
					console.log(this.update_list.phonenumber);
				})
			},

			//获取填写地址
			update_deptName(e) {
				this.update_list.deptName = e.detail.value
			},
			//是否提交界面
			btn_show() {
				var phone = this.update_list.phonenumber
				var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
				if (strTemp.test(phone) && this.update_list.deptName != '') {
					console.log('手机验证通过');
					this.$refs.popup.show() // 显示
					console.log(this.update_list, 'this.update_list');
				} else if (!strTemp.test(phone)) {
					uni.showToast({
						title: '请输入正确手机',
						icon: 'error'
					})
				} else if (this.update_list.deptName == '') {
					uni.showToast({
						title: '单位地址为空',
						icon: 'error'
					})
				}
			},
			//隐藏弹出框
			is_hide() {
				this.$refs.popup.hide() // 隐藏
				//取消清除内容
				this.update_list.phonenumber = ''
				this.update_list.deptName = ''
			},
			//确认提交信息
			agree() {
				this.$https.post('maintainModifyInfo', {
					phonenumber: this.update_list.phonenumber,
					deptName: this.update_list.deptName
				}).then(res => {
					if (res.code == 200) {
						this.$refs.popup.hide() // 隐藏
						uni.showToast({
							title: "提交成功",
							icon: 'none'
						})
						setTimeout(() => {
							this.$refs.popup.hide() // 隐藏
							uni.navigateBack({
								delta: '1'
							})
						}, 1500)
					} else {
						uni.showToast({
							title: "请修改正确的维保单位",
							icon: 'none'
						})
						this.$refs.popup.hide() // 隐藏
					}
					console.log(res, 'res');
				})

			}
		}
	}
</script>

<style lang="scss">

</style>
